const koaRouter = require('koa-router');
const path = require('path');
const { sep } = path;
const glob = require('glob');

module.exports = (app) => {
    const routerPath = path.resolve(app.bisinessPath, `.${sep}router`);
    const router = new koaRouter();

    const fileList = glob.sync(path.resolve(routerPath, `.${sep}**${sep}**.js`));
    fileList.forEach((file) => {
        require(path.resolve(file))(app, router)
    });
    app.use(router.routes());
    app.use(router.allowedMethods());

    router.get('*', async (ctx) => {
        ctx.status = 302;
        ctx.redirect(app?.options?.homePage ?? '/api/project/model_list');
    })

}